<?php

// Acceso restringido
defined('JL') or die('Acceso restringido');

class PartenairesModel extends JLModelBase {

    function getPartenaires() {
        $sql = "SELECT 
              `id_int_partenaire`,
              `int_page`,
              `int_id_state`
            FROM 
              `tbl_partenaires`";

        $this->DB->executeQuery($sql);
        return ($this->DB->getRowsAffected() > 0) ? $this->DB->getDataArray() : null;
    }

    function insert($int_page, $int_id_state) {
        $sql = "INSERT INTO 
              `tbl_partenaires`
            (
              `int_page`,
              `int_id_state`
            ) 
            VALUE (
              " . $this->DB->Quote($int_page) . ",
              " . $this->DB->Quote($int_id_state) . " )";

        $this->DB->executeQuery($sql);
        return ($this->DB->getRowsAffected() > 0) ? true : false;
    }

    function countPartenaires() {
        $sql = "SELECT 
              COUNT(`id_int_partenaire`) AS COUNT
            FROM 
              `tbl_partenaires`";

        $this->DB->executeQuery($sql);
        $data = $this->DB->getDataArray();

        return intval($data[0]['COUNT']);
    }

    function delete($id_int_partenaire) {
        $sql = "DELETE FROM 
              `tbl_partenaires` 
            WHERE 
              `id_int_partenaire` = " . $this->DB->Quote($id_int_partenaire) . " AND `int_id_state` <> 1";
        $this->DB->executeQuery($sql);

        return ($this->DB->getRowsAffected() > 0) ? true : false;
    }

}